# -*- coding: utf8 -*-
import os

import requests

base_dir = os.getcwd()
dest_dir = base_dir + "/images"
if not os.path.exists(dest_dir):
    os.mkdir(base_dir + "/images")

source_dir = os.path.dirname(os.path.abspath(__file__)) + "/image.txt"
f = open(file=source_dir, mode="r")
header = {"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"}

f.readline()
for line in f:
    urls = (line.strip("\n")).split(",")[2]
    res = requests.get(url=urls, headers=header)
    filename = dest_dir + "/" +line.split(",")[1].replace("/","") + ".jpg"
    ftmp = open(file=filename, mode="wb")
    ftmp.write(res.content)
    ftmp.close()
f.close()
